package com.yc.damai.biz;

import java.util.List;
import java.util.Map;

import com.yc.damai.util.DBHelper;

public class CartDao {
	
	/**
	 * JDBC 可以自动转换数据类型 
	 * @param id
	 * @param pid
	 * @param count
	 */
	public void insert(Integer uid, String pid, String count) {
		String sql = "insert into cart values(null,?,?,?)";
		DBHelper.update(sql, uid, pid, count);
	}
	
	public int updateCount(Integer uid, String pid, String count) {
		String sql = "update cart set count = count + ? where uid=? and pid=?";
		return DBHelper.update(sql, count, uid, pid);
	}
	
	public List<Map<String, Object>> queryCartInfo(Integer uid){
		String sql = "select * from cart c join product p on c.pid=p.pid where c.uid=?";
		return DBHelper.query(sql, uid);
	}

}
